package com.ruoyi.common.utils.android;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;

public class DecryptString {

    private static String f961e = "4879448401768944";
    private static DecryptString f;
    private SecretKeySpec a;

    private IvParameterSpec f962c;
    private byte[] b = f961e.getBytes();

    String f963d = "1311678945347452";

    public DecryptString() {
        this.a = null;
        try {
            this.a = new SecretKeySpec(this.f963d.getBytes("UTF-8"), "AES");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        }
        this.f962c = new IvParameterSpec(this.b);
    }

    private byte[] a(String str, SecretKey secretKey, IvParameterSpec ivParameterSpec, byte[] bArr) {

        System.out.println("DecryptString,bArr size = " + bArr.length);
        try {
            Cipher instance = Cipher.getInstance(str);
            instance.init(2, secretKey, ivParameterSpec);
            return instance.doFinal(bArr);
        } catch (Exception e2) {
            e2.printStackTrace();
            return null;
        }
    }

    private byte[] b(String str, SecretKey secretKey, IvParameterSpec ivParameterSpec, byte[] bArr) {
        try {
            Cipher instance = Cipher.getInstance(str);
            instance.init(1, secretKey, ivParameterSpec);
            return instance.doFinal(bArr);
        } catch (Exception unused) {
            unused.printStackTrace();
            return null;
        }
    }

    public static DecryptString getInstance() {
        if (f == null) {
            synchronized (DecryptString.class) {
                if (f == null) {
                    f = new DecryptString();
                }
            }
        }
        return f;
    }

    public String decrypt(String str) {
        try {
            return new String(a("AES/CBC/PKCS5Padding", this.a, this.f962c, com.ruoyi.common.utils.android.a.decodeBase64(str)));
        } catch (Exception unused) {
            return str;
        }
    }

    public String encrypt(String str) {
        try {
            return new String(com.ruoyi.common.utils.android.a.encodeBase64(b("AES/CBC/PKCS5Padding", this.a, this.f962c, str.getBytes("UTF-8"))));
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
            return "";
        }
    }


    public void setsKey(String str) {
        this.f963d = str;
        try {
            this.a = new SecretKeySpec(this.f963d.getBytes("UTF-8"), "AES");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        }
    }

    public static void main(String[] args) {
        DecryptString decrypt = new DecryptString();
        String encryptStr = decrypt.encrypt("hello world");
        System.out.println("encryptStr: " + encryptStr);
        String decryptStr = decrypt.decrypt(encryptStr);
        System.out.println("decryptStr: " + decryptStr);

        String str = "vf64ROrXVXFp7bG5f8jDIwirdweyPnVqu7dtlAb3IiPER3sGBJj+X1p4G1uPxlAmVMFNObduPY1/qXHt5D+zbZeqvRZmFVUFi2S82IiAKzo97LkdSygIoEa+UUtwAN0NSwF83j7YAB7iu1bS7vtUKYgYZx2Z5qunGTQpHZF9c3XS/Xt6Nhx4b9mn6X1yp9PttRdU106RjMZtRqfr0BtVUUeff+Q+KChdNju/q15Q/4gvQqB2mKh6z1Hx29dpUaloiFLXcS7RU5sV0U3kJJfDsR76BPNxNPy/INJNlpOUwEF7heZ5WGam6CmGCz13Mvb+/2yIFiDxZLsCH4ekNstUncvPVBmp/S3i5K7zn0YEIcItR8sGNNn46lRE2RNc/iGiiEplMR1zbHlVIhsrEb2zBtJO5mgAXzMTSZ+KmNq+7XQJReReAJ+2vl9engSVxZDww3yrxL5nJOs2699Zf6eogwT1684fMOeTxscQ/srnwDWWcNNZChkQpbJ/1y6mB707eJYQ8PwnHe1EgpXC0ZTZRtgTnBozasgT/nJhV+a6BZpROlaxjI+IshYmwWMFz17+P9691wxzlOrp//pM2QaAKMe3JlfNj+WtE9e5k0zZvTcX0D58BBau8QrQ84pAA1dWVDaduBy9L4VJapQboUcbdvKmzWsQZYq0aeZ5Sxsik0Q4uN63xzDKqdOuN7hky0OVIci2TZlRJJ8+kgWRQQJ59IBxBCWjlJUhIsy/0TYCxw6uYJ9DdYFucejULiJfZQj6dMmzZPTbKhLjsEh27pDvgv4Sf8AYBtHjqO8mWIvBojgxJGtulGCQBcCw3qFlm8sTrA6UriXrmSIrJh+h619MZDDFLwLYrOa9BqxBNVogskm9Hqva5jC87dXVPgZul7/RUl4axbZ3Z86j78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9fGJWRYFqXpYf2dUnWcJ+um/QLdR/TNskMQpQjUa3B4BJ0zhDyIAf6Ggsg6EwXzjZFua56zE4YBQ5mJl20LOkudpNBuSOebmcb8olKFj9PR7GtNxTjEpWOWRtGgZAReaTXDexCt8xSzg7NX9KKrKSNLe+r7ohin0n+HgOc48NtSj4UXIKlY0CaS+ZhNvYbD65lgk4NWRJRfDE1mCk00fzNP/OOiFrWDXy+HkBU4fXkrCadJOkzItXRcR8cV1aD5wNp+TRv9wz3HVxuNOVC8Ue624+La5Q/jAKQA8n3Tyn5ydABbcVitQyvvW6H5PeV2yp4r3z5e0JnCI1V4HCx0t4FEYPayoV0D+f5OhBR24/jRBjzSqgEuQht71qJgNR05TDZcSMXQeYvbLJ4e67QumOQkVxfu8HqQk8QJlrQa00keUyRsaYbewaQ2VE/d706zh0sLP3tzGbBtRcvk25wI+UN2LkSakySurEjatl6I08iw7OLD9nTwda7dtduAHLEVuxqArELrNuMvDklXXH4+WOeWlT6SUSozIJbOp/xsvuk9onCO3PSISJDQ3wN0HEXI4S74lsQG3Zm7Hh8KEPrvs0jatOwZvwU1UDZji/Q0WmRtfdnHzx3cf/Fk5E7m0AT8g6ROA3knOStiQfzXxRyHQ/VZlaivR/CPAOUhbBdVDKbDcwKk1ZAWq72j7RMa1gUsglkqG0Bb1fYIWCDiH2m7irUCSpEHFH5ftql4dPaMJnCL2kcS9D/IvbX3yEQnkedx1Wf8mp1HNfu4CKkGbiD5XjrCh4ae50kz8b6BOtBDzhP2Q5Ib3zDowcKz+Tmk+SR0c8zOpkG4R80npWnRAPbHoDmfDMHk=";
        String result1 = decrypt.decrypt(str);
        System.out.println("result1: " + result1);

        DecryptString.getInstance().setsKey("3178172413845564");
        String result = DecryptString.getInstance().decrypt(str);
        System.out.println("result:" + result);

    }

}
